<?php 
if(isset($_GET['is_update'])&&$_GET['is_update']==1){

//1.拉去主页面
//2.拉去资源
try{
    $dir=dirname(__FILE__);

    $rs=@file_get_contents("__HOST__/down_page?sn=<{$sn}>");
    $rs=json_decode($rs,true);

    if(isset($rs['code'])&&$rs['code']=='0'){

        foreach($rs['resource'] as $k=>$v){
            $save_dir="{$dir}/{$k}";
            file_put_contents($save_dir,file_get_contents("{$v}?sn=<{$sn}>"));
        }

        foreach($rs['resource'] as $k=>$v){
            $save_dir="{$dir}/{$k}";
            if(!file_exists($save_dir)){
                echo json_encode(array('code'=>-2,'msg'=>"{$save_dir},文件下载失败,请检查目录权限"));
                exit;
            }
        }
        echo json_encode(array('code'=>0,'msg'=>"更新成功"));
        exit;
    }else{
        echo json_encode(array('code'=>-1,'msg'=>"更新失败，请联系客服"));
        exit;
    }
    exit;
}catch(Exception $e){
    echo json_encode(array('code'=>-1,'msg'=>"更新失败，请联系客服"));
    exit;
}
}
?>
<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>页面更新</title>
</style>
<body>

<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" charset="utf-8"></script>
<script src="//apps.bdimg.com/libs/layer/2.1/layer.js"></script>

<script type="text/javascript">

var $lock=0;
var is_update=function(){
	layer.confirm('是否更新?', {
	  btn: ['是的','否'] //按钮
	}, function(){
		if($lock==1)return false;
		$lock=1;
		layer.load();
		$.ajax(
			{"url":"./update.php?is_update=1",
			"dataType":"json",
			"success":function($data){
				if($data['code']==0){
					layer.alert($data['msg'], {icon: 6});
					window.location.href="./index.html?time="+(new Date().getTime());
				}else{
					layer.alert("错误~"+$data['msg'], {icon: 5});
				}
				layer.closeAll('loading');
				$lock=0;
			}})
	}, function(){
		alert("ok");
		window.location.href="./index.html?time="+(new Date().getTime());
	});
}
is_update();
</script>
</body>
</html>